const glob = require("glob")
const titles = require('./title.js')

try {
    entries = glob('src/pages/**/*.js', { sync: true })
} catch (err) {
    entries = []
    throw err
}
let pages = {}
let commonConfig = {
    template: 'public/index.html',
}

entries.forEach((page) => {
    var filename = page.substring(page.lastIndexOf('\/') + 1, page.lastIndexOf('.'))
    pages[filename] = {
        entry: page,
        filename: filename + '.html',
        title: titles[filename],
        chunks: ['chunk-vendors', 'chunk-common', filename],
        ...commonConfig
    }
})

module.exports = pages